package com.stox.ui.javafx.core.widget.wrapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.OrderComparator;

import com.stox.util.ApplicationContextUtil;

public class ContextMenu extends javafx.scene.control.ContextMenu implements InitializingBean {

	public ContextMenu() {
		super();
	}

	public ContextMenu(MenuItem... paramVarArgs) {
		super(paramVarArgs);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Collection<MenuItem> menuItems = ApplicationContextUtil.getApplicationContext().getBeansOfType(MenuItem.class).values();
		List<MenuItem> children = new ArrayList<MenuItem>();
		for(MenuItem menuItem : menuItems){
			if(getClass().equals(menuItem.getParentClass())){
				children.add(menuItem);
			}
		}
		OrderComparator.sort(children);
		getItems().addAll(children);
	}
	
}
